home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Control del ratón / Scribble / Scribble.cs next >
Encoding:
Text File  |  2002-04-18  |  1.3 KB  |  53 lines

  1. //---------------------------------------
  2. // Scribble.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class Scribble: Form
  9. {
  10.      bool  bTracking;
  11.      Point ptLast;
  12.  
  13.      public static void Main()
  14.      {
  15.           Application.Run(new Scribble());
  16.      }
  17.      public Scribble()
  18.      {
  19.           Text = "Forma libre";
  20.           BackColor = SystemColors.Window;
  21.           ForeColor = SystemColors.WindowText;
  22.      }
  23.      protected override void OnMouseDown(MouseEventArgs mea)
  24.      {
  25.           if (mea.Button != MouseButtons.Left)
  26.                return;
  27.  
  28.           ptLast = new Point(mea.X, mea.Y);
  29.           bTracking = true;
  30.      }
  31.      protected override void OnMouseMove(MouseEventArgs mea)
  32.      {
  33.           if (!bTracking)
  34.                return;
  35.  
  36.           Point ptNew = new Point(mea.X, mea.Y);
  37.           
  38.           Graphics grfx = CreateGraphics();
  39.           grfx.DrawLine(new Pen(ForeColor), ptLast, ptNew);
  40.           grfx.Dispose();
  41.  
  42.           ptLast = ptNew;
  43.      }
  44.      protected override void OnMouseUp(MouseEventArgs mea)
  45.      {
  46.           bTracking = false;
  47.      }
  48.      protected override void OnPaint(PaintEventArgs pea)
  49.      {
  50.           // ┐QuΘ hago aquφ?
  51.      }
  52. }
  53.